import torch
import clip
from PIL import Image

device = "cuda" if torch.cuda.is_available() else "cpu"
model, preprocess = clip.load("ViT-B/32", device=device)
# checkpoint = torch.load("clip_epoch_90.pth")
# model.load_state_dict(checkpoint)
# print(model)
image = preprocess(Image.open("python/interfence/000_0000.jpg")).unsqueeze(0).to(device)
text = clip.tokenize(["a photo of one person", "a photo of two person"]).to(device)
# print(text.shape)
# print(text[2] == text[3])
# print(text[2])
with torch.no_grad():
    image_features = model.encode_image(image)
    text_features = model.encode_text(text)

    logits_per_image, logits_per_text = model(image, text)
    print(logits_per_image)
    print(logits_per_text)
    # print(image_features)
    # print(text_features)
    probs = logits_per_image.softmax(dim=-1).cpu().numpy()

print("Label probs:", probs)  # prints: [[0.9927937  0.00421068 0.00299572]]
